'use strict';

/* Controllers */

var iswitchControllers = angular.module('iswitchControllers', []);

iswitchControllers.controller('directoryListCtrl', ['$scope', 'directory',
  function($scope, directory) {
   // $scope.directories = directory.query();
 $scope.orderProp = 'owner';
  $scope.loadDirectories = function (response) {	
	if (response) {
		$scope.directories=response;
		console.log($scope.directories);	
	}
		$scope.waitMessage = null;

  };
  $scope.directories = directory.getDirectoryList('{}').success($scope.loadDirectories);
  }]);

iswitchControllers.controller('directoryDetailCtrl', ['$scope', '$routeParams', 'directory',
    function ($scope,$routeParams,directory){
  $scope.loadDirectory = function (response) {	
	if (response) {
		$scope.directory=response;
		console.log($scope.directory);	
	}
		$scope.waitMessage = null;

  }; 
   console.log($scope.phoneId); 
console.log($routeParams.phoneId); 
$scope.directory=  directory.getdirectory("{ \"extention\":" + $routeParams.phoneId+ "}").success($scope.loadDirectory);

    $scope.setImage = function(imageUrl) {
      $scope.mainImageUrl = imageUrl;
    }

$scope.save = function (){
$scope.waitMessage = "ok";
//	alert("js save");
       // var Polyg = this.Polygon;
directory.update($scope.directory).success(function (response) {
	if (response) {
		$scope.message = response;
		$scope.success = true;
		$scope.directory = angular.copy($scope.directory);
	}
	$scope.waitMessage = null;
	});

};


  }]);
